#import "CellStyleDynamic.h"
#import "CellDataModel.h"
#import "CellFrame.h"
#import "UIImageView+WebCache.h"
#import "DynamicEntity.h"
#import "ScreenAdapter.h"
#import "SDWebImageManager.h"
#import "ImageUtil.h"
#import "ImageMediator.h"
#import "PopUIManager.h"

static UITableView* m_tableView;

@implementation CellStyleDynamic

@synthesize user_icon,user_nick_name, user_title,user_content,img01,img01button,img02,img02button,img03,img03button,img04,img04button,img05,img05button,img06,img06button,img07,img07button,img08,img08button,img09,img09button,img10,img10button,user_timestamp;

@synthesize title01,title02,title03,title04,title05,title06,plugin01,plugin01button,plugin02,plugin02button,plugin03,plugin03button,plugin04,plugin04button,plugin05,plugin05button,plugin06,plugin06button;

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier rowID:(NSInteger)rid{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        // 让自定义Cell和系统的cell一样, 一创建出来就拥有一些子控件提供给我们使用
        // 1.创建头像
        user_icon = [[UIImageView alloc] init];
        [self addSubview:user_icon];
        
        // 2.创建昵称
        user_nick_name = [[UILabel alloc] init];
        user_nick_name.textColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.6 alpha:1];
        user_nick_name.font = [UIFont systemFontOfSize:15];
        [self addSubview:user_nick_name];

//       3.创建标题
        user_title = [[UILabel alloc]init];
        user_title.numberOfLines = 1;
        user_title.font = [UIFont systemFontOfSize:16];
        user_title.textColor = UIColorMake(45, 45, 45);
        [self addSubview:user_title];
        
        // 4.创建正文
        user_content = [[UILabel alloc] init];
        user_content.numberOfLines = 0;
        user_content.font = [UIFont systemFontOfSize:16];
        user_content.textColor = UIColorMake(45, 45, 45);
//         introLabel.backgroundColor = [UIColor greenColor];
        [self addSubview:user_content];
        
        // 5.创建配图
//       ===================================
        img01 = [[UIImageView alloc] init];
        [img01 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        img01.contentMode =  UIViewContentModeScaleAspectFill;
        img01.clipsToBounds  = YES;
        [self addSubview:img01];
        
        img01button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:img01button];
        [self.img01button addTarget:self action:@selector(img01Click:) forControlEvents:UIControlEventTouchUpInside];
        
        img02 = [[UIImageView alloc] init];
        [img02 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        img02.contentMode =  UIViewContentModeScaleAspectFill;
        img02.clipsToBounds  = YES;
        [self addSubview:img02];
        
        img02button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:img02button];
        [self.img02button addTarget:self action:@selector(img02Click:) forControlEvents:UIControlEventTouchUpInside];
        
        img03 = [[UIImageView alloc] init];
        [img03 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        img03.contentMode =  UIViewContentModeScaleAspectFill;
        img03.clipsToBounds  = YES;
        [self addSubview:img03];

        
        img03button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:img03button];
        [self.img03button addTarget:self action:@selector(img03Click:) forControlEvents:UIControlEventTouchUpInside];

        
        img04 = [[UIImageView alloc] init];
        [img04 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        img04.contentMode =  UIViewContentModeScaleAspectFill;
        img04.clipsToBounds  = YES;
        [self addSubview:img04];

        
        img04button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:img04button];
        [self.img04button addTarget:self action:@selector(img04Click:) forControlEvents:UIControlEventTouchUpInside];
        
        
        img05 = [[UIImageView alloc] init];
        [img05 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        img05.contentMode =  UIViewContentModeScaleAspectFill;
        img05.clipsToBounds  = YES;
        [self addSubview:img05];


        img05button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:img05button];
        [self.img05button addTarget:self action:@selector(img05Click:) forControlEvents:UIControlEventTouchUpInside];

        
        img06 = [[UIImageView alloc] init];
        [img06 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        img06.contentMode =  UIViewContentModeScaleAspectFill;
        img06.clipsToBounds  = YES;
        [self addSubview:img06];
        img06button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:img06button];
        [self.img06button addTarget:self action:@selector(img06Click:) forControlEvents:UIControlEventTouchUpInside];

        img07 = [[UIImageView alloc] init];
        [img07 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        img07.contentMode =  UIViewContentModeScaleAspectFill;
        img07.clipsToBounds  = YES;
        [self addSubview:img07];
        img07button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:img07button];
        [self.img07button addTarget:self action:@selector(img07Click:) forControlEvents:UIControlEventTouchUpInside];

        img08 = [[UIImageView alloc] init];
        [img08 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        img08.contentMode =  UIViewContentModeScaleAspectFill;
        img08.clipsToBounds  = YES;
        [self addSubview:img08];
        img08button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:img08button];
        [self.img08button addTarget:self action:@selector(img08Click:) forControlEvents:UIControlEventTouchUpInside];

        img09 = [[UIImageView alloc] init];
        [img09 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        img09.contentMode =  UIViewContentModeScaleAspectFill;
        img09.clipsToBounds  = YES;
        [self addSubview:img09];
        img09button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:img09button];
        [self.img09button addTarget:self action:@selector(img09Click:) forControlEvents:UIControlEventTouchUpInside];

        
        img10 = [[UIImageView alloc] init];
        [img10 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        img10.contentMode =  UIViewContentModeScaleAspectFill;
        img10.clipsToBounds  = YES;
        [self addSubview:img10];
        img10button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:img10button];
        [self.img10button addTarget:self action:@selector(bigimgClick:) forControlEvents:UIControlEventTouchUpInside];
        
//        ==================================
        //创建作业1
        plugin01 = [[UIImageView alloc] init];
        [plugin01 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        plugin01.contentMode =  UIViewContentModeScaleAspectFill;
        plugin01.clipsToBounds  = YES;
        [self addSubview:plugin01];
        
        _plugin01Shade =  [[UIImageView alloc] init];
        [_plugin01Shade setContentScaleFactor:[[UIScreen mainScreen] scale]];
        _plugin01Shade.contentMode =  UIViewContentModeScaleAspectFill;
        _plugin01Shade.clipsToBounds  = YES;
        [self addSubview:_plugin01Shade];
        
        plugin01button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:plugin01button];
        [self.plugin01button addTarget:self action:@selector(plugin01Click:) forControlEvents:UIControlEventTouchUpInside];
        title01 = [[UILabel alloc]init];
        title01.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
        title01.font = [UIFont systemFontOfSize:13];
        title01.textAlignment = NSTextAlignmentCenter;
        [self addSubview:title01];
        
        //创建作业2
        plugin02 = [[UIImageView alloc] init];
        [plugin02 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        plugin02.contentMode =  UIViewContentModeScaleAspectFill;
        plugin02.clipsToBounds  = YES;
        [self addSubview:plugin02];
        
        _plugin02Shade =  [[UIImageView alloc] init];
        [_plugin02Shade setContentScaleFactor:[[UIScreen mainScreen] scale]];
        _plugin02Shade.contentMode =  UIViewContentModeScaleAspectFill;
        _plugin02Shade.clipsToBounds  = YES;
        [self addSubview:_plugin02Shade];
        
        plugin02button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:plugin02button];
        [self.plugin02button addTarget:self action:@selector(plugin02Click:) forControlEvents:UIControlEventTouchUpInside];
        title02 = [[UILabel alloc]init];
        title02.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
        title02.font = [UIFont systemFontOfSize:13];
        title02.textAlignment = NSTextAlignmentCenter;
        [self addSubview:title02];
        
        //创建作业3
        plugin03 = [[UIImageView alloc] init];
        [plugin03 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        plugin03.contentMode =  UIViewContentModeScaleAspectFill;
        plugin03.clipsToBounds  = YES;
        [self addSubview:plugin03];
        plugin03button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:plugin03button];
        
        _plugin03Shade =  [[UIImageView alloc] init];
        [_plugin03Shade setContentScaleFactor:[[UIScreen mainScreen] scale]];
        _plugin03Shade.contentMode =  UIViewContentModeScaleAspectFill;
        _plugin03Shade.clipsToBounds  = YES;
        [self addSubview:_plugin03Shade];
        
        [self.plugin03button addTarget:self action:@selector(plugin03Click:) forControlEvents:UIControlEventTouchUpInside];
        title03 = [[UILabel alloc]init];
        title03.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
        title03.font = [UIFont systemFontOfSize:13];
        title03.textAlignment = NSTextAlignmentCenter;
        [self addSubview:title03];
        
        //创建作业4
        plugin04 = [[UIImageView alloc] init];
        [plugin04 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        plugin04.contentMode =  UIViewContentModeScaleAspectFill;
        plugin04.clipsToBounds  = YES;
        [self addSubview:plugin04];
        plugin04button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:plugin04button];
        
        _plugin04Shade =  [[UIImageView alloc] init];
        [_plugin04Shade setContentScaleFactor:[[UIScreen mainScreen] scale]];
        _plugin04Shade.contentMode =  UIViewContentModeScaleAspectFill;
        _plugin04Shade.clipsToBounds  = YES;
        [self addSubview:_plugin04Shade];
        
        [self.plugin04button addTarget:self action:@selector(plugin04Click:) forControlEvents:UIControlEventTouchUpInside];
        title04 = [[UILabel alloc]init];
        title04.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
        title04.font = [UIFont systemFontOfSize:13];
        title04.textAlignment = NSTextAlignmentCenter;
        [self addSubview:title04];
        
        //创建作业5
        plugin05 = [[UIImageView alloc] init];
        [plugin05 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        plugin05.contentMode =  UIViewContentModeScaleAspectFill;
        plugin05.clipsToBounds  = YES;
        [self addSubview:plugin05];
        plugin05button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:plugin05button];
        
        _plugin05Shade =  [[UIImageView alloc] init];
        [_plugin05Shade setContentScaleFactor:[[UIScreen mainScreen] scale]];
        _plugin05Shade.contentMode =  UIViewContentModeScaleAspectFill;
        _plugin05Shade.clipsToBounds  = YES;
        [self addSubview:_plugin05Shade];
        
        [self.plugin05button addTarget:self action:@selector(plugin05Click:) forControlEvents:UIControlEventTouchUpInside];
        title05 = [[UILabel alloc]init];
        title05.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
        title05.font = [UIFont systemFontOfSize:13];
        title05.textAlignment = NSTextAlignmentCenter;
        [self addSubview:title05];
        
        //创建作业6
        plugin06 = [[UIImageView alloc] init];
        [plugin06 setContentScaleFactor:[[UIScreen mainScreen] scale]];
        plugin06.contentMode =  UIViewContentModeScaleAspectFill;
        plugin06.clipsToBounds  = YES;
        [self addSubview:plugin06];
        plugin06button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:plugin06button];
        
        _plugin06Shade =  [[UIImageView alloc] init];
        [_plugin06Shade setContentScaleFactor:[[UIScreen mainScreen] scale]];
        _plugin06Shade.contentMode =  UIViewContentModeScaleAspectFill;
        _plugin06Shade.clipsToBounds  = YES;
        [self addSubview:_plugin06Shade];
        
        [self.plugin06button addTarget:self action:@selector(plugin06Click:) forControlEvents:UIControlEventTouchUpInside];
        title06 = [[UILabel alloc]init];
        title06.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
        title06.font = [UIFont systemFontOfSize:13];
        title06.textAlignment = NSTextAlignmentCenter;
        [self addSubview:title06];
        
        
        // 6.创建时间戳
        user_timestamp = [[UILabel alloc] init];
        // nameLabel.backgroundColor = [UIColor redColor];
        user_timestamp.font = [UIFont systemFontOfSize:10];
        user_timestamp.textColor = UIColorMake(148, 148, 148);
        [self addSubview:user_timestamp];
    }
    return self;
}

-(void)plugin01Click:(id)sender{
    [[PopUIManager getInstanse] popAlertView:self title:@"提示1" message:@"请先下载宝贝云计划" cancelButtonTitle:@"确定"];
}

-(void)plugin02Click:(id)sender{
    [[PopUIManager getInstanse] popAlertView:self title:@"提示2" message:@"请先下载宝贝云计划" cancelButtonTitle:@"确定"];

}

-(void)plugin03Click:(id)sender{
    [[PopUIManager getInstanse] popAlertView:self title:@"提示3" message:@"请先下载宝贝云计划" cancelButtonTitle:@"确定"];

}

-(void)plugin04Click:(id)sender{
    [[PopUIManager getInstanse] popAlertView:self title:@"提示4" message:@"请先下载宝贝云计划" cancelButtonTitle:@"确定"];

}

-(void)plugin05Click:(id)sender{
    [[PopUIManager getInstanse] popAlertView:self title:@"提示5" message:@"请先下载宝贝云计划" cancelButtonTitle:@"确定"];

}

-(void)plugin06Click:(id)sender{
    [[PopUIManager getInstanse] popAlertView:self title:@"提示6" message:@"请先下载宝贝云计划" cancelButtonTitle:@"确定"];

}

-(void)img01Click:(id)sender{
    UIButton *btn = (UIButton*)sender;
    UITableViewCell* cell = nil;
    //解决ios7 ios8版本差异引起的问题
    if (IS_LOW_IOS8) {
        cell = (UITableViewCell*)[[btn superview]superview];
    }else{
        cell = (UITableViewCell*)[btn superview];
    }
    NSInteger index = [m_tableView indexPathForCell:cell].row;
    
    [[ImageMediator getInstanse] cellAtIndex:index imageAtIndex:1];
}

-(void)img02Click:(id)sender{
    UIButton *btn = (UIButton*)sender;
    UITableViewCell* cell = nil;
    //解决ios7 ios8版本差异引起的问题
    if (IS_LOW_IOS8) {
        cell = (UITableViewCell*)[[btn superview]superview];
    }else{
        cell = (UITableViewCell*)[btn superview];
    }
    NSInteger index = [m_tableView indexPathForCell:cell].row;
    
    [[ImageMediator getInstanse] cellAtIndex:index imageAtIndex:2];
}

-(void)img03Click:(id)sender{
    UIButton *btn = (UIButton*)sender;
    UITableViewCell* cell = nil;
    //解决ios7 ios8版本差异引起的问题
    if (IS_LOW_IOS8) {
        cell = (UITableViewCell*)[[btn superview]superview];
    }else{
        cell = (UITableViewCell*)[btn superview];
    }
    NSInteger index = [m_tableView indexPathForCell:cell].row;
    
    [[ImageMediator getInstanse] cellAtIndex:index imageAtIndex:3];
}

-(void)img04Click:(id)sender{
    UIButton *btn = (UIButton*)sender;
    UITableViewCell* cell = nil;
    //解决ios7 ios8版本差异引起的问题
    if (IS_LOW_IOS8) {
        cell = (UITableViewCell*)[[btn superview]superview];
    }else{
        cell = (UITableViewCell*)[btn superview];
    }
    NSInteger index = [m_tableView indexPathForCell:cell].row;
    
    [[ImageMediator getInstanse] cellAtIndex:index imageAtIndex:4];
}

-(void)img05Click:(id)sender{
    UIButton *btn = (UIButton*)sender;
    UITableViewCell* cell = nil;
    //解决ios7 ios8版本差异引起的问题
    if (IS_LOW_IOS8) {
        cell = (UITableViewCell*)[[btn superview]superview];
    }else{
        cell = (UITableViewCell*)[btn superview];
    }
    NSInteger index = [m_tableView indexPathForCell:cell].row;
    
    [[ImageMediator getInstanse] cellAtIndex:index imageAtIndex:5];
}

-(void)img06Click:(id)sender{
    UIButton *btn = (UIButton*)sender;
    UITableViewCell* cell = nil;
    //解决ios7 ios8版本差异引起的问题
    if (IS_LOW_IOS8) {
        cell = (UITableViewCell*)[[btn superview]superview];
    }else{
        cell = (UITableViewCell*)[btn superview];
    }
    NSInteger index = [m_tableView indexPathForCell:cell].row;
    
    [[ImageMediator getInstanse] cellAtIndex:index imageAtIndex:6];
}

-(void)img07Click:(id)sender{
    UIButton *btn = (UIButton*)sender;
    UITableViewCell* cell = nil;
    //解决ios7 ios8版本差异引起的问题
    if (IS_LOW_IOS8) {
        cell = (UITableViewCell*)[[btn superview]superview];
    }else{
        cell = (UITableViewCell*)[btn superview];
    }
    NSInteger index = [m_tableView indexPathForCell:cell].row;
    
    [[ImageMediator getInstanse] cellAtIndex:index imageAtIndex:7];
}

-(void)img08Click:(id)sender{
    UIButton *btn = (UIButton*)sender;
    UITableViewCell* cell = nil;
    //解决ios7 ios8版本差异引起的问题
    if (IS_LOW_IOS8) {
        cell = (UITableViewCell*)[[btn superview]superview];
    }else{
        cell = (UITableViewCell*)[btn superview];
    }
    NSInteger index = [m_tableView indexPathForCell:cell].row;
    
    [[ImageMediator getInstanse] cellAtIndex:index imageAtIndex:8];
}

-(void)img09Click:(id)sender{
    UIButton *btn = (UIButton*)sender;
    UITableViewCell* cell = nil;
    //解决ios7 ios8版本差异引起的问题
    if (IS_LOW_IOS8) {
        cell = (UITableViewCell*)[[btn superview]superview];
    }else{
        cell = (UITableViewCell*)[btn superview];
    }
    NSInteger index = [m_tableView indexPathForCell:cell].row;
    
    [[ImageMediator getInstanse] cellAtIndex:index imageAtIndex:9];
}

-(void)bigimgClick:(id)sender{
    UIButton *btn = (UIButton*)sender;
    UITableViewCell* cell = nil;
    //解决ios7 ios8版本差异引起的问题
    if (IS_LOW_IOS8) {
        cell = (UITableViewCell*)[[btn superview]superview];
    }else{
        cell = (UITableViewCell*)[btn superview];
    }
    NSInteger index = [m_tableView indexPathForCell:cell].row;
    
    [[ImageMediator getInstanse] cellAtIndex:index imageAtIndex:10];
}

+ (instancetype)cellWithTableView:(UITableView *)tableView rowID:(NSInteger)rid
{
    static NSString *identifier = @"status";
    m_tableView = tableView;
    // 1.缓存中取
    CellStyleDynamic *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    // 2.创建
    if (cell == nil) {
        cell = [[CellStyleDynamic alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier rowID:rid];
        }
    return cell;
}

- (void)setDataFrame:(CellFrame *)cellFrame
{
    _dataFrame = cellFrame;
    // 1.给子控件赋值数据
    [self settingData];
    // 2.设置frame
    [self settingFrame];
}


/**
 *  设置子控件的数据
 */
- (void)settingData
{
    CellDataModel *temp_model = self.dataFrame.model;
    // 设置头像
    [self.user_icon setImage:[UIImage imageNamed:@"default_circle_icon"]];
    if (![temp_model.icon isEqualToString:@"null"]) {
        [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:temp_model.icon] options:SDWebImageLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize) {
//            NSLog(@"进度: %ld",(long)receivedSize);
        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
            image = [[ImageUtil getInstance] circleImage:image withParam:0];
            [self.user_icon setImage:image];
        }];
    }
    
    // 设置昵称
    self.user_nick_name.text = temp_model.nickname;
    
    //设置title
    self.user_title.text = temp_model.title;

    // 设置内容
    self.user_content.text = temp_model.content;
    
    // 设置配图
    if (![temp_model.image1 isEqualToString:@""]) {// 有配图
        [self.img01 sd_setImageWithURL:[NSURL URLWithString:temp_model.image1] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.img01.hidden = NO;
    }else
    {
        self.img01.hidden = YES;
    }
    
    if (![temp_model.image2 isEqualToString:@""]) {// 有配图
        [self.img02 sd_setImageWithURL:[NSURL URLWithString:temp_model.image2] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.img02.hidden = NO;
    }else
    {
        self.img02.hidden = YES;
    }
    
    if (![temp_model.image3 isEqualToString:@""]) {// 有配图
        [self.img03 sd_setImageWithURL:[NSURL URLWithString:temp_model.image3] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.img03.hidden = NO;
    }else
    {
        self.img03.hidden = YES;
    }
    
    if (![temp_model.image4 isEqualToString:@""]) {// 有配图
        [self.img04 sd_setImageWithURL:[NSURL URLWithString:temp_model.image4] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.img04.hidden = NO;
    }else
    {
        self.img04.hidden = YES;
    }
    if (![temp_model.image5 isEqualToString:@""]) {// 有配图
        [self.img05 sd_setImageWithURL:[NSURL URLWithString:temp_model.image5] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.img05.hidden = NO;
    }else
    {
        self.img05.hidden = YES;
    }
    if (![temp_model.image6 isEqualToString:@""]) {// 有配图
        [self.img06 sd_setImageWithURL:[NSURL URLWithString:temp_model.image6] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.img06.hidden = NO;
    }else
    {
        self.img06.hidden = YES;
    }
    if (![temp_model.image7 isEqualToString:@""]) {// 有配图
        [self.img07 sd_setImageWithURL:[NSURL URLWithString:temp_model.image7] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.img07.hidden = NO;
    }else
    {
        self.img07.hidden = YES;
    }
    if (![temp_model.image8 isEqualToString:@""]) {// 有配图
        [self.img08 sd_setImageWithURL:[NSURL URLWithString:temp_model.image8] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.img08.hidden = NO;
    }else
    {
        self.img08.hidden = YES;
    }
    if (![temp_model.image9 isEqualToString:@""]) {// 有配图
        [self.img09 sd_setImageWithURL:[NSURL URLWithString:temp_model.image9] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.img09.hidden = NO;
    }else
    {
        self.img09.hidden = YES;
    }
    if (![temp_model.image10 isEqualToString:@""]) {// 有配图
        [self.img10 sd_setImageWithURL:[NSURL URLWithString:temp_model.image10] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.img10.hidden = NO;
    }else
    {
        self.img10.hidden = YES;
    }
    
    //作业配图1
    if (temp_model.plugin1 != nil && [temp_model.plugin1 count] != 0) {
        [self.plugin01 sd_setImageWithURL:[NSURL URLWithString:[temp_model.plugin1 objectForKey:@"logo_url"]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.plugin01.hidden = NO;
        self.title01.text = [temp_model.plugin1 objectForKey:@"title"];
        self.title01.hidden = NO;
        
        [self.plugin01Shade setImage:[UIImage imageNamed:@"shade"]];
        self.plugin01button.hidden = NO;
        self.plugin01Shade.hidden = NO;
        
    }else
    {
        self.title01.hidden = YES;
        self.plugin01.hidden = YES;
        self.plugin01button.hidden = YES;
        _plugin01Shade.hidden = YES;
    }
    
    //作业配图2
    if (temp_model.plugin2 != nil && [temp_model.plugin2 count] != 0) {
        [self.plugin02 sd_setImageWithURL:[NSURL URLWithString:[temp_model.plugin2 objectForKey:@"logo_url"]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.plugin02.hidden = NO;
        self.title02.text = [temp_model.plugin2 objectForKey:@"title"];
        self.title02.hidden = NO;
        [self.plugin02Shade setImage:[UIImage imageNamed:@"shade"]];
        self.plugin02button.hidden = NO;
        self.plugin02Shade.hidden = NO;
    }else
    {
        self.title02.hidden = YES;
        self.plugin02.hidden = YES;
        self.plugin02button.hidden = YES;
        _plugin02Shade.hidden = YES;
    }
    
    //作业配图3
    if (temp_model.plugin3 != nil && [temp_model.plugin3 count] != 0) {
        [self.plugin03 sd_setImageWithURL:[NSURL URLWithString:[temp_model.plugin3 objectForKey:@"logo_url"]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.plugin03.hidden = NO;
        self.title03.text = [temp_model.plugin3 objectForKey:@"title"];
        self.title03.hidden = NO;
        [self.plugin03Shade setImage:[UIImage imageNamed:@"shade"]];
        self.plugin03button.hidden = NO;
        self.plugin03Shade.hidden = NO;
    }else
    {
        self.title03.hidden = YES;
        self.plugin03.hidden = YES;
        self.plugin03button.hidden = YES;
        _plugin03Shade.hidden = YES;
    }
    
    //作业配图4
    if (temp_model.plugin4 != nil && [temp_model.plugin4 count] != 0) {
        [self.plugin04 sd_setImageWithURL:[NSURL URLWithString:[temp_model.plugin4 objectForKey:@"logo_url"]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.plugin04.hidden = NO;
        self.title04.text = [temp_model.plugin4 objectForKey:@"title"];
        self.title04.hidden = NO;
        [self.plugin04Shade setImage:[UIImage imageNamed:@"shade"]];
        self.plugin04button.hidden = NO;
        self.plugin04Shade.hidden = NO;
    }else
    {
        self.title04.hidden = YES;
        self.plugin04.hidden = YES;
        self.plugin04button.hidden = YES;
        _plugin04Shade.hidden = YES;
    }
    
    //作业配图5
    if (temp_model.plugin5 != nil && [temp_model.plugin5 count] != 0) {
        [self.plugin05 sd_setImageWithURL:[NSURL URLWithString:[temp_model.plugin5 objectForKey:@"logo_url"]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.plugin05.hidden = NO;
        self.title05.text = [temp_model.plugin5 objectForKey:@"title"];
        self.title05.hidden = NO;
        [self.plugin05Shade setImage:[UIImage imageNamed:@"shade"]];
        self.plugin05button.hidden = NO;
        self.plugin05Shade.hidden = NO;
    }else
    {
        self.title05.hidden = YES;
        self.plugin05.hidden = YES;
        self.plugin05button.hidden = YES;
        _plugin05Shade.hidden = YES;
    }
    
    //作业配图6
    if (temp_model.plugin6 != nil && [temp_model.plugin6 count] != 0) {
        [self.plugin06 sd_setImageWithURL:[NSURL URLWithString:[temp_model.plugin6 objectForKey:@"logo_url"]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.plugin06.hidden = NO;
        self.title06.text = [temp_model.plugin6 objectForKey:@"title"];
        self.title06.hidden = NO;
        [self.plugin06Shade setImage:[UIImage imageNamed:@"shade"]];
        self.plugin06button.hidden = NO;
        self.plugin06Shade.hidden = NO;
    }else
    {
        self.title06.hidden = YES;
        self.plugin06.hidden = YES;
        self.plugin06button.hidden = YES;
        _plugin06Shade.hidden = YES;
    }
    
    self.user_timestamp.text = temp_model.timestamp;
}
/**
 *  设置子控件的frame
 */
- (void)settingFrame
{
    
    // 设置头像的frame
    self.user_icon.frame = self.dataFrame.iconF;
    
    // 设置昵称的frame
    self.user_nick_name.frame = self.dataFrame.nameF;
    
    //设置标题的frame
    self.user_title.frame = self.dataFrame.titleF;
    
    // 设置正文的frame
    self.user_content.frame = self.dataFrame.contentF;
    
    // 设置配图的frame
    if (![self.dataFrame.model.image1 isEqualToString:@""]) {// 有配图
        self.img01.frame = self.dataFrame.img01F;
        self.img01button.frame = self.dataFrame.img01ButtonF;
    }
    if (![self.dataFrame.model.image2 isEqualToString:@""]) {// 有配图
        self.img02.frame = self.dataFrame.img02F;
        self.img02button.frame = self.dataFrame.img02ButtonF;
    }
    if (![self.dataFrame.model.image3 isEqualToString:@""]) {// 有配图
        self.img03.frame = self.dataFrame.img03F;
        self.img03button.frame = self.dataFrame.img03ButtonF;
    }
    if (![self.dataFrame.model.image4 isEqualToString:@""]) {// 有配图
        self.img04.frame = self.dataFrame.img04F;
        self.img04button.frame = self.dataFrame.img04ButtonF;
    }
    if (![self.dataFrame.model.image5 isEqualToString:@""]) {// 有配图
        self.img05.frame = self.dataFrame.img05F;
        self.img05button.frame = self.dataFrame.img05ButtonF;
    }
    if (![self.dataFrame.model.image6 isEqualToString:@""]) {// 有配图
        self.img06.frame = self.dataFrame.img06F;
        self.img06button.frame = self.dataFrame.img06ButtonF;
    }
    if (![self.dataFrame.model.image7 isEqualToString:@""]) {// 有配图
        self.img07.frame = self.dataFrame.img07F;
        self.img07button.frame = self.dataFrame.img07ButtonF;
    }
    if (![self.dataFrame.model.image8 isEqualToString:@""]) {// 有配图
        self.img08.frame = self.dataFrame.img08F;
        self.img08button.frame = self.dataFrame.img08ButtonF;
    }
    if (![self.dataFrame.model.image9 isEqualToString:@""]) {// 有配图
        self.img09.frame = self.dataFrame.img09F;
        self.img09button.frame = self.dataFrame.img09ButtonF;
    }
    if (![self.dataFrame.model.image10 isEqualToString:@""]) {// 有配图
        self.img10.frame = self.dataFrame.img10F;
        self.img10button.frame = self.dataFrame.img10ButtonF;
    }
    
    if (self.dataFrame.model.plugin1 != nil && [self.dataFrame.model.plugin1 count] != 0) {
        self.title01.frame = self.dataFrame.title01F;
        self.plugin01.frame = self.dataFrame.plugin01F;
        self.plugin01button.frame = self.dataFrame.plugin01ButtonF;
        self.plugin01Shade.frame = self.dataFrame.plugin01F;
    }
    if (self.dataFrame.model.plugin2 != nil && [self.dataFrame.model.plugin2 count] != 0) {
        self.title02.frame = self.dataFrame.title02F;
        self.plugin02.frame = self.dataFrame.plugin02F;
        self.plugin02button.frame = self.dataFrame.plugin02ButtonF;
        self.plugin02Shade.frame = self.dataFrame.plugin02F;
    }
    if (self.dataFrame.model.plugin3 != nil && [self.dataFrame.model.plugin3 count] != 0) {
        self.title03.frame = self.dataFrame.title03F;
        self.plugin03.frame = self.dataFrame.plugin03F;
        self.plugin03button.frame = self.dataFrame.plugin03ButtonF;
        self.plugin03Shade.frame = self.dataFrame.plugin03F;
    }
    if (self.dataFrame.model.plugin4 != nil && [self.dataFrame.model.plugin4 count] != 0) {
        self.title04.frame = self.dataFrame.title04F;
        self.plugin04.frame = self.dataFrame.plugin04F;
        self.plugin04button.frame = self.dataFrame.plugin04ButtonF;
        self.plugin04Shade.frame = self.dataFrame.plugin04F;
    }
    if (self.dataFrame.model.plugin5 != nil && [self.dataFrame.model.plugin5 count] != 0) {
        self.title05.frame = self.dataFrame.title05F;
        self.plugin05.frame = self.dataFrame.plugin05F;
        self.plugin05button.frame = self.dataFrame.plugin05ButtonF;
        self.plugin05Shade.frame = self.dataFrame.plugin05F;
    }
    if (self.dataFrame.model.plugin6 != nil && [self.dataFrame.model.plugin6 count] != 0) {
        self.title06.frame = self.dataFrame.title06F;
        self.plugin06.frame = self.dataFrame.plugin06F;
        self.plugin06button.frame = self.dataFrame.plugin06ButtonF;
        self.plugin06Shade.frame = self.dataFrame.plugin06F;
    }
    
    self.user_timestamp.frame = self.dataFrame.timestampF;
}

/**
 *  计算文本的宽高
 *
 *  @param str     需要计算的文本
 *  @param font    文本显示的字体
 *  @param maxSize 文本显示的范围
 *
 *  @return 文本占用的真实宽高
 */
- (CGSize)sizeWithString:(NSString *)str font:(UIFont *)font maxSize:(CGSize)maxSize
{
    NSDictionary *dict = @{NSFontAttributeName : font};
    // 如果将来计算的文字的范围超出了指定的范围,返回的就是指定的范围
    // 如果将来计算的文字的范围小于指定的范围, 返回的就是真实的范围
    CGSize size = [str boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
    return size;
}

- (void)awakeFromNib {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
